package cn.sirun.com.fca.account.repo.reset;

import com.tencent.cloud.iov.kernel.constant.ApiConst;
import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.service.ServiceGenerator;

import cn.sirun.com.fca.account.model.base.CaptchaRequest;
import cn.sirun.com.fca.account.model.base.ResendResponse;
import cn.sirun.com.fca.account.model.base.SRPEncryptInfo;
import cn.sirun.com.fca.account.model.base.SubmitPasswordRequest;
import cn.sirun.com.fca.account.model.base.SubmitPhoneRequest;
import cn.sirun.com.fca.account.model.base.SubmitPhoneResponse;
import cn.sirun.com.fca.account.model.register.SubmitEmailRequest;
import io.reactivex.Observable;

/**
 * @author vinsonhuang
 * @date 2018/5/16
 */

public class ResetRepository {

    private static volatile ResetRepository sInstance;

    public static ResetRepository getInstance() {
        if (sInstance == null) {
            synchronized (ResetRepository.class) {
                if (sInstance == null) {
                    sInstance = new ResetRepository();
                }
            }
        }

        return sInstance;
    }

    private final ResetService mResetService;

    private ResetRepository() {
        mResetService = ServiceGenerator.createService(ResetService.class, ApiConst.getBaseUrl());
    }

    public Observable<BaseResponse<SubmitPhoneResponse>> submitPhone(SubmitPhoneRequest request) {
        return mResetService.submitPhone(request);
    }

    public Observable<BaseResponse<SRPEncryptInfo>> submitCaptcha(String code) {
        return mResetService.submitCaptcha(new CaptchaRequest(code));
    }

    public Observable<BaseResponse<Void>> setPassword(String password) {
        return mResetService.setPassword(new SubmitPasswordRequest(password));
    }

    public Observable<BaseResponse<ResendResponse>> resend() {
        return mResetService.resend();
    }


    public Observable<BaseResponse<SubmitPhoneResponse>> submitEmail(SubmitEmailRequest request) {
        return mResetService.submitEmail(request);
    }

    public Observable<BaseResponse<SRPEncryptInfo>> submitEmialCaptcha(String code) {
        return mResetService.submitEmialCaptcha(new CaptchaRequest(code));
    }

    public Observable<BaseResponse<Void>> setEmailPassword(String password) {
        return mResetService.setEmailPassword(new SubmitPasswordRequest(password));
    }

    public Observable<BaseResponse<ResendResponse>> emialResend() {
        return mResetService.emailResend();
    }
}
